﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreGallery.Addins.Contracts;
using System.IO;
using System.Windows.Media.Imaging;
using System.ComponentModel;

/*
Base photo type contains image-related data
Providers can map base photo to underlying photo via ID mapping

1. Main UI gets generic photo from PhotoManager (thumb, metadata, ref to provider)
2. Providers responsible for importing/exporting photos
3. Addins work with photo, submit to PhotoManager
4. PhotoManager submits back to original provider to sync state
5. Provider may update its store, or general metadata, then returns to PhotoManager
5. PhotoManager commits general data as needed 
*/

namespace CoreGallery.Addins.Contracts
{

    public class BasePhoto : INotifyPropertyChanged
    {
        private string _filename, _name, _subject;
        private long _width, _height;
        private Guid _id;
        private IList<MetadataElement> _metadata = new List<MetadataElement>();
        private BitmapDecoder decoder;

        public BasePhoto(Guid id)
        {
            _id = id;
        }

        public BasePhoto()
        {
            _id = Guid.NewGuid();
        }

        public Guid UniqueId
        {
            get { return _id; }
        }

        public IList<MetadataElement> Metadata
        {
            get { return _metadata; }
        }

        public string Title
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    OnPropertyChanged("Title");
                }
            }
        }

        public long Width
        {
            get { return _width; }
            set
            {
                if (_width != value)
                {
                    _width = value;
                    OnPropertyChanged("Width");
                }
            }
        }

        public long Height
        {
            get { return _height; }
            set
            {
                if (_height != value)
                {
                    _height = value;
                    OnPropertyChanged("Height");
                }
            }
        }

        public System.IO.Stream GetPhotoStream()
        {
            return File.OpenRead(_filename);
        }

        public System.IO.Stream GetThumbnailStream()
        {
            return File.OpenRead(_filename);
        }


        public string Subject
        {
            get { return _subject; }
            set
            {
                if (_subject != value)
                {
                    _subject = value;
                    OnPropertyChanged("Subject");
                }
            }
        }

        public string Description
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Creator
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Publisher
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Contributor
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public DateTime Date
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Type
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Format
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Identifier
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Relation
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Coverage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #region INotifyPropertyChanged Members

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler ph = PropertyChanged;
            if (ph != null)
            {
                ph(this, new PropertyChangedEventArgs(name));
            }
        }


        #endregion
    }
}
